using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Main;

namespace AtletIS.Database.Mapping.Main
{
    public class StatisticMap : EntityTypeConfiguration<Statistic>
    {
        public StatisticMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.sResult)
                .HasMaxLength(100);

            this.Property(t => t.Rank)
                .HasMaxLength(10);

            this.Property(t => t.Note)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("Statistics");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.CompetitorId).HasColumnName("CompetitorId");
            this.Property(t => t.CompetitionId).HasColumnName("CompetitionId");
            this.Property(t => t.DisciplineId).HasColumnName("DisciplineId");
            this.Property(t => t.Year).HasColumnName("Year");
            this.Property(t => t.Result).HasColumnName("Result");
            this.Property(t => t.sResult).HasColumnName("sResult");
            this.Property(t => t.Rank).HasColumnName("Rank");
            this.Property(t => t.Indoor).HasColumnName("Indoor");
            this.Property(t => t.Electronic).HasColumnName("Electronic");
            this.Property(t => t.Note).HasColumnName("Note");

            // Relationships
            this.HasOptional(t => t.Competitor)
                .WithMany(t => t.Statistics)
                .HasForeignKey(d => d.CompetitorId);
            this.HasOptional(t => t.Discipline)
                .WithMany(t => t.Statistics)
                .HasForeignKey(d => d.DisciplineId);
            this.HasOptional(t => t.StatisticsCompetition)
                .WithMany(t => t.Statistics)
                .HasForeignKey(d => d.CompetitionId);

        }
    }
}
